import controller.User;

import java.io.InputStream;
import java.sql.*;
import java.util.Properties;

public class Main {
    public static void main(String[] args) {


        /**
         *  前端  html css js(jQuery)   vue、react
         */
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        try {
            InputStream inputStream = Main.class.getClassLoader().getResourceAsStream("jdbc.properties");
            Properties properties = new Properties();
            properties.load(inputStream);
            Class.forName(properties.getProperty("driver"));
            connection = DriverManager.getConnection(properties.getProperty("url"), properties.getProperty("username"), properties.getProperty("password"));
//            Statement statement = connection.createStatement();
//            ResultSet resultSet = statement.executeQuery("select * from user");
            String sql = "select * from user";
            preparedStatement = connection.prepareStatement(sql);
            resultSet = preparedStatement.executeQuery();
            User user = null;
            while (resultSet.next()) {
                int id = resultSet.getInt("id");
                String name = resultSet.getString("username");
                String password = resultSet.getString("password");
                user = new User(id, name, password);
            }
            System.out.println(user);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }finally {
            try {
                if (resultSet != null) {
                    resultSet.close();
                }else if (preparedStatement != null) {
                    preparedStatement.close();
                }else if (connection != null) {
                    connection.close();
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }


        }
    }
}
